

const mongoose = require('mongoose');

var express = require('express')
// 注意这里的声明
var auth = express()
// const controller= require("../../controller/controllerenter")

const {returnDatas}= require("../../util/returnDatas/index");
const { auth_service } = require('../../service/impl/auth_service/index');
// const { auth_bean } = require('../../beans/impl/auth_bean/index');


auth.post('/post/auth/add', async (req,res) => {
  let result
  try {
    let news  = req.body.news
    result =  await auth_service.getIns().create(news)
  } catch (error) {
    console.log(error);
    res.send(returnDatas(false,null,error))
    return
  }
  res.send(returnDatas(true,result))
  })
  
  auth.post('/post/auth/delete', async (req,res) => {
    let result
    try {
      let  id  = req.body.conditions.id
      result =  await auth_service.getIns().findByIdAndDelete(id)
    } catch (error) {
      console.log(error);
      res.send(returnDatas(false,null,error))
      return
    }
    res.send(returnDatas(true,result))
  })
  
  auth.post('/post/auth/update', async (req,res) => {
    let result
    try {
      let  id  = req.body.conditions.id
      let updates = req.body.updates
      result =  await auth_service.getIns().findByIdAndUpdate(id,updates)
    } catch (error) {
      console.log(error);
      res.send(returnDatas(false,null,error))
      return
    }
    res.send(returnDatas(true,result))
  })
  
  auth.post('/post/auth/query', async (req,res) => {
    let result
    try {
      result =  await auth_service.getIns().find()
    } catch (error) {
      console.log(error);
      res.send(returnDatas(false,null,error))
      return
    }
    res.send(returnDatas(true,result))
  })
  
  module.exports= auth